﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Epona.Domain.Query.Impl
{
    public class InCriterion:BasicCriterion
    {
        public ICollection Value { get; private set; }

        public InCriterion(string propName,ICollection value)
            :base(propName)
        {
            if (value != null) this.Value = value;
        }

        public InCriterion(string propName,object[] value)
            :base(propName)
        {
            if (value != null && value.Length > 0)
                this.Value = value as ICollection;
        }

        public override string ToQueryString()
        {
            if (Value == null || Value.Count == 0)
            {
                return "1 > 1";
            }
            return GetPropNameWithAlias() + " in " + GetParamNameWithColon();
        }

        public override NamedParameters GetParameters()
        {
            NamedParameters result = NamedParameters.Create();
            if(Value.Count!=0)
            {
                result = result.Add(GetParamName(), Value);
            }
            return result;
        }
    }
}
